﻿namespace StringsAndTextProcessing
{
    using System;
    using System.Collections.Generic;

    class ExtractSentencesByWord
    {
        // 1.2.13.08. Write a program that extracts from a given text all sentences containing given word.
        // Example: The word is "in". The text is:
        // We are living in a yellow submarine. We don't have anything else. Inside the submarine is very tight.
        // So we are drinking all the day. We will move out of it in 5 days.
        // The expected result is:
        // We are living in a yellow submarine. We will move out of it in 5 days.
        // Consider that the sentences are separated by "." and the words – by non-letter symbols.

        static void Main()
        {
            var text = "We are living in  a yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days.";
            var word = "in";
            var splittedText = text.Split('.');
            var newText = new List<string>();

            for (int i = 0; i < splittedText.Length; i++)
            {
                var splitWhiteSpaces = new string[splittedText[i].Length];
                splitWhiteSpaces = splittedText[i].Split(' ');
                for (int j = 0; j < splitWhiteSpaces.Length; j++)
                {
                    if (splitWhiteSpaces[j].ToLower() == word)
                    {
                        newText.Add(splittedText[i]);
                        break;
                    }
                }
            }

            Console.WriteLine(string.Join(".\n ", newText));
        }
    }
}